﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.UPMS.Model.SystemPart;
using NHibernate.Criterion;
using Castle.ActiveRecord;
using ZDSoft.UPMS.Model.BusinessPart;
namespace ZDSoft.UPMS.Manager.SystemPart
{
    public class UserManager : ManagerBase<User>
    {

        public User Login(string account, string password)
        {
            IList<ICriterion> conditions = new List<ICriterion>();
            conditions.Add(Expression.Eq("IsActive", true));
            conditions.Add(Expression.Eq("Account", account));
            conditions.Add(Expression.Eq("Password", password));
            IList<User> list = Find(conditions);
            if (list == null || list.Count == 0)
            {
                return null;
            }
            else
            {
                return list[0];
            }
        }
        public IList<User> FindStudent()
        {
            IList<User> UserList = base.FindAll();
            IList<User> StudentList = new List<User>();
            for (int i = 0; i < UserList.Count; i++)
            {
                if (UserList[i].Roles[0].Name == "学生")
                {
                    StudentList.Add(UserList[i]);
                }
            }
            return StudentList;
        }
        public IList<Organization> findall()
        {
            return new Manager.BusinessPart.OrganizationManager().FindAll();
        }
        public Organization Getone(int id)
        {
            return new Manager.BusinessPart.OrganizationManager().FindByID(id);
        }
        public IList<Course> GetAllCourse()
        {
            return new Manager.BusinessPart.CourseManager().FindAll();
        }
    }
}
